<%--
  Created by IntelliJ IDEA.
  User: Colorful
  Date: 2023/8/17
  Time: 8:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="path" value="${pageContext.request.contextPath }"/>
<html>
<head>
    <title>我的评论</title>
    <script rel="script" src="${path}/js/jquery-3.6.4.js"></script>
    <link rel="stylesheet" type="text/css" href="${path}/css/userComments.css">
</head>
<body>
<div class="comment-container">
    <div class="profile-title">
        我的评论
    </div>
    <div class="comment_box">
        <c:set var="commentList" value="${requestScope.commentList}"/>
        <c:set var="user_id" value="${sessionScope.user.user_id}"/>
        <c:choose>
            <c:when test="${empty commentList}">
                <script>
                    window.location="${path}/CommentUserServlet?prom=userSelComment&user_id=${user_id}";
                </script>
            </c:when>
            <c:otherwise>
                <c:forEach var="cl" items="${commentList}">
                    <div id="${cl.comment_id}">
                        <div class="comment_header">
                            <span class="user_image"><img src="${path}/images/userAvatar/${cl.image}"></span>
                            <span class="userName">${cl.userName}</span>
                            <span class="comment_date">${cl.comment_time}</span>
<%--                            <span class="wGood_img"></span>--%>
                            <span class="rGood_img"></span>
                            <span class="goodCount">${cl.comment_good}</span>
                            <span class="del_comment" onclick="del_comment(${cl.comment_id})"></span>
                        </div>
                        <div class="comment_body">
                            <div class="poster">
                                <img src="${path}/images/moviePicture/${cl.movie_picture}">
                            </div>
                            <div class="comment_content">
                                <div class="movie-name">${cl.movie_cn_name}</div>
                                <div class="">${cl.content}</div>
                            </div>
                        </div >
                    </div>
                </c:forEach>
            </c:otherwise>
        </c:choose>
        <c:set var="pages" value="${sessionScope.page}"/>
        <div style="text-align: center;width: 878px;">
            <p style="display: inline-block">当前页数：[${pages.currPageNo}/${pages.totalPageCount}]
                <c:if test="${pages.currPageNo>1}">
            <form style="display: inline-block" method="post" action="${path}/CommentUserServlet?prom=userSelComment&pageIndex=1&user_id=${user_id}">
                <input type="submit" value="首页" class="n1">
            </form>
            <form style="display: inline-block" method="post" action="${path}/CommentUserServlet?prom=userSelComment&pageIndex=${pages.currPageNo-1}&user_id=${user_id}">
                <input type="submit" value="上一页" class="n1" >
            </form>
            </c:if>
            <c:if test="${pages.currPageNo<pages.totalPageCount}">
                <form style="display: inline-block" method="post" action="${path}/CommentUserServlet?prom=userSelComment&pageIndex=${pages.currPageNo+1}&user_id=${user_id}">
                    <input type="submit" value="下一页" class="n1">
                </form>
                <form style="display: inline-block" method="post" action="${path}/CommentUserServlet?prom=userSelComment&pageIndex=${pages.totalPageCount}&user_id=${user_id}">
                    <input type="submit" value="末页" class="n1">
                </form>
            </c:if>
            </p>
        </div>
    </div>
</div>
<script>
    function del_comment(commentId) {
        var str=confirm("您确定要删除该评论嘛？删除后，不可恢复～");
        if (str){
            $.post("${path}/CommentUserServlet?prom=delUserComment","&commentId="+commentId,function (result) {
                if (result>0){
                    alert("删除成功！");
                    $("#"+commentId).remove();
                }else {

                    alert(result);
                    alert("删除失败")
                }
            },"text");
        }
    }
</script>
</body>
</html>
